package com.pkx.cloud.fse7.expand.plan.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.pkx.cloud.fse7.expand.plan.entity.DoorPlanDetail;
import com.pkx.cloud.fse7.expand.plan.repo.DoorPlanDetailMapper;
import com.pkx.cloud.fse7.expand.plan.service.DoorPlanDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
 * 服务实现类
 *
 * @author chenwg
 * @since 2021-04-09
 */
@Service
@DS("slave")
public class DoorPlanDetailServiceImpl extends ServiceImpl<DoorPlanDetailMapper, DoorPlanDetail> implements DoorPlanDetailService {

    /**
     * 分页列表
     *
     * @param doorPlanDetail
     * @return
     */
    @Override
    public Page<DoorPlanDetail> pageList(Page page, DoorPlanDetail doorPlanDetail) {
        LambdaQueryWrapper<DoorPlanDetail> lambdaQueryWrapper = Wrappers.lambdaQuery(DoorPlanDetail.class);
        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param doorPlanDetail
     * @return
     */
    @Override
    public List<DoorPlanDetail> listByEntity(DoorPlanDetail doorPlanDetail) {
        LambdaQueryWrapper<DoorPlanDetail> lambdaQueryWrapper = Wrappers.lambdaQuery(DoorPlanDetail.class);
        lambdaQueryWrapper.eq(DoorPlanDetail::getPlanId, doorPlanDetail.getPlanId());
        return list(lambdaQueryWrapper);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public DoorPlanDetail selectById(String id) {
        return getById(id);
    }

    /**
     * 保存
     *
     * @param doorPlanDetail
     * @return
     */
    @Override
    public Boolean saveDoorPlanDetail(DoorPlanDetail doorPlanDetail) {
        return save(doorPlanDetail);
    }

    /**
     * 修改
     *
     * @param doorPlanDetail
     * @return
     */
    @Override
    public Boolean modify(DoorPlanDetail doorPlanDetail) {
        return updateById(doorPlanDetail);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deleteById(String id) {
        return removeById(id);
    }

    @Override
    public Boolean deleteByPlantId(String id) {
        List<DoorPlanDetail> list = lambdaQuery().eq(DoorPlanDetail::getPlanId, id)
                .select(DoorPlanDetail::getId)
                .list();
        if (!list.isEmpty()) {
            List<String> collect = list.stream().map(DoorPlanDetail::getId).collect(Collectors.toList());
            return removeByIds(collect);
        }
        return false;
    }

    @Override
    public Boolean deleteByPlantIds(List<String> ids) {
        List<DoorPlanDetail> list = lambdaQuery().in(DoorPlanDetail::getPlanId, ids)
                .select(DoorPlanDetail::getId)
                .list();
        if (!list.isEmpty()) {
            List<String> collect = list.stream().map(DoorPlanDetail::getId).collect(Collectors.toList());
            return removeByIds(collect);
        }
        return false;
    }
}
